import { ReqPage, ResPage } from '@/api/interface'
import { TBY } from '@/api/config/servicePort'
import http from '@/api'

export namespace JointDefence {
  /**查询参数 */
  export interface Query extends ReqPage {
    title?: string
    type?: number
    publish?: number
  }

  /**列表内容 */
  export interface Record {
    id: number
    title: string
    type: number
    createTimeFormat: string
  }

  /**详情 */
  export interface Form {
    id: number
    title: string
    type: number
    createTime: string
    content: string
  }

  export const TypeEnum = [
    { value: 1, label: '“林长+司法”工作机制' },
    { value: 2, label: '乡镇、村毗邻区域护林联防' },
    { value: 3, label: '部门协调联动机制' }
  ]
}

// 分页查询
export const pageJointDefence = (params: JointDefence.Query) => {
  return http.get<ResPage<JointDefence.Record>>(TBY + `/joint_defence/page`, params)
}

// 列表查询
export const listJointDefence = (params: JointDefence.Query) => {
  return http.get<JointDefence.Record[]>(TBY + `/joint_defence/list`, params)
}

// 详情信息
export const getJointDefenceDetail = (id: number) => {
  return http.get<Partial<JointDefence.Form>>(TBY + `/joint_defence/get`, { id }, { loading: false })
}

// 新增或修改
export const saveOrUpdateJointDefence = (params: Partial<JointDefence.Form>) => {
  return http.post(TBY + `/joint_defence/save`, params)
}

// 删除
export const removeJointDefence = (id: number) => {
  return http.delete(TBY + `/joint_defence/delete`, { id })
}

// 设置上下架
export const setRelease = (id: number, publish: number) => {
  return http.get(TBY + `/joint_defence/release`, { id, publish })
}
